package fr.pascal.client.activity;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

import fr.pascal.client.ClientFactory;
import fr.pascal.client.place.DetailPlace;
import fr.pascal.client.ui.ListView;

public class ListActivity extends AbstractActivity implements ListView.Presenter {
	
	private ClientFactory clientFactory;
	private int animalId;
	
	public ListActivity(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}
	
	public ListActivity(ClientFactory clientFactory, DetailPlace detailPlace) {
		this.clientFactory = clientFactory;
		this.animalId = Integer.valueOf(detailPlace.getAnimalId());
	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		ListView listView = clientFactory.getListView();
		listView.setPresenter(this);
		listView.setStyle(animalId);
		panel.setWidget(listView.asWidget());
	}

	@Override
	public void onClickAnimal(int animalId) {
		clientFactory.getPlaceController().goTo(new DetailPlace(Integer.toString(animalId)));
	}
}
